import Vue from 'vue'
import VueRouter from 'vue-router'
import Home from '../views/Home.vue'

//获取原型对象上的push函数
const originalPush = VueRouter.prototype.push
//修改原型对象中的push方法
VueRouter.prototype.push = function push(location) {
  return originalPush.call(this, location).catch(err => err)
}

Vue.use(VueRouter)

const routes = [
  {
    path: '/',
    name: 'Home',
    component: Home,
    redirect: '/article-publish',
    children: [
      {
        path: '/article-publish',
        name: 'ArticlePublish',
        meta: {
          title: '发布文章'
        },
        component: () => import('../views/article/publish.vue')
      },
      {
        path: '/article-history',
        name: 'ArticleHistory',
        meta: {
          title: '历史文章'
        },
        component: () => import('../views/article/history.vue')
      }
    ]
  },
  {
    path:'/login',
    name: 'Login',
    meta: {
      title: '登录'
    },
    component: () => import('../views/Login.vue')
  }
]

const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes
}) 

export default router
